package com.xiaoxu.scala_base.三班._1_Scala集合

object ArrayApp extends App {


  /**
    * 静态数组
    */

  // 可以直接在机器上运行演示
  val a = new Array[String](3)
  a.length
  a(1) = "hello"
  a(1)

  val b = Array("hadoop", "spark", "storm")

  val c = Array(2, 3, 4, 5, 6, 7, 8, 9)
  // 求和
  c.sum
  c.min
  c.max
  //数组转换为字符串
  c.mkString("<",",",">")
  val cStr = c.mkString(",")
  println(" cStr" + cStr)

  println(c.toArray.mkString)





  /**
    *  todo 动态数组
    */
  val array = scala.collection.mutable.ArrayBuffer[Int]()

  array += 1
  array += 2
  array += (3, 4, 5)
  array ++= Array(6, 7, 8)
  array.insert(0, 0)
  array.remove(1)
  array.remove(0, 3)
  //从最后开始删除几个元素
  array.trimEnd(2)


    for(i <- 0 until c.length) {
      println(c(i))
    }

    for(ele <- c) {
      println(ele)
    }

  for (i <- (0 until array.length).reverse) {
    println(array(i))
  }





}
